import {genCancelNs} from './genCancelNs';

export const genSchedule = (cancelNs) => {
    const _cancelNs = cancelNs||genCancelNs();
    return {
        cancelNs:_cancelNs,
        timeout:(ns,fn,delay)=>{
            const tHandler = setTimeout(fn, delay);
            const cancel=() => {
                clearTimeout(tHandler);
            };
            return _cancelNs.add(ns,fn,cancel);
        },
        interval:(ns,fn,delay)=>{
            const tHandler = setInterval(fn, delay);
            const cancel=() => {
                clearInterval(tHandler);
            };
            return _cancelNs.add(ns,fn,cancel);
        },
    };
};

export default genSchedule;